package com.ash.service.user;

import com.ash.domain.User;
import com.ash.domain.vo.UserVo;
import com.ash.mapper.user.UserMapper;
import com.ash.util.PojoUtil;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/20 12:29
 * @file : project06.com.ash.service.user.UserServiceImpl.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public List<UserVo> selectAll(String uname,Integer page, Integer limit) {
        return userMapper.selectAll(uname,(page-1)*limit,limit);
    }

    @Override
    public User selectToLogin(User user) {
        return userMapper.selectToLogin(user);
    }

    @Override
    public User selectNameToRegister(String uname) {
        return userMapper.selectNameToRegister(uname);
    }
    @Override
    public int addToRegister(User user) {
        return userMapper.addToRegister(user);
    }

    @Override
    public int delete(int uid) {
        return userMapper.delete(uid);
    }

    @Override
    public int dataCount(@Nullable String uname) {
        return userMapper.dataCount(uname);
    }

    @Override
    public Integer deleteByIds(List<Integer> ids) {
        if(ids.size()!=0){
           return userMapper.deleteByIds(ids);
        }
        return 0;
    }

    @Override
    public int update(User user) {
        return userMapper.update(PojoUtil.beanToMap(user).entrySet(),user.getUid());
    }

    @Override
    public User selectById(Integer uid) {
        return userMapper.selectById(uid);
    }
}
